package vip.xiaonuo.smzq.modular.jsc.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.jsc.entity.Kczyly;
import vip.xiaonuo.smzq.modular.jsc.mapper.KczylyMapper;
import vip.xiaonuo.smzq.modular.jsc.service.IKczylyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * 驾驶舱矿产资源利用统计 服务实现类
 *
 * @author sqq
 * @since 2024-05-13
 */
@Service
public class KczylyServiceImpl extends ServiceImpl<KczylyMapper, Kczyly> implements IKczylyService {

    @Resource
    private KczylyMapper kczylyMapper;

    @Override
    public Page<Kczyly> page(Kczyly kczyly) {
        QueryWrapper<Kczyly> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public void add(Kczyly kczyly) {
        if (kczyly.getXzqhdm() != null&& kczyly.getNd() != null ){
            kczylyMapper.delete(new QueryWrapper<Kczyly>().eq("xzqhdm",kczyly.getXzqhdm()).eq("nd",kczyly.getNd()));
            kczylyMapper.insert(kczyly);
        }
    }

    @Override
    public List<Kczyly> kczylyList(Integer nd, String xzqhdm) {
        QueryWrapper<Kczyly> queryWrapper = new QueryWrapper<>();
        if (nd != null){
            queryWrapper.eq("nd",nd);
        }
        if (xzqhdm != null){
            queryWrapper.eq("xzqhdm",xzqhdm);
        }
        return kczylyMapper.selectList(queryWrapper);
    }
}
